package com.onpositive.notes.android.ui.elements;

import com.onpositive.notes.android.main.CollectionsActivity;
import com.onpositive.notes.android.main.MainActivity;
import com.onpositive.notes.android.main.NotesActivity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.RelativeLayout;

public class MenuUI {
	
	public View createView( final Context context ){
		
		RelativeLayout lt = new RelativeLayout( context ) ;
		
		Button notesListButton = new Button(context) ;
		notesListButton.setText("Notes List") ;
		
		notesListButton.setOnClickListener( new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent( context, NotesActivity.class);
				context.startActivity(intent);				
			}
		}) ;
		
		Button collectionsButton = new Button(context) ;
		collectionsButton.setText("Collections List") ;
		collectionsButton.setOnClickListener( new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent( context, CollectionsActivity.class);
				context.startActivity(intent);				
			}
		}) ;
		
		Button deleteButton = new Button(context) ;
		deleteButton.setText("Delete Data And Exit") ;
		deleteButton.setOnClickListener( new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if( !(context instanceof MainActivity) )
					return ;
				
				MainActivity activity = (MainActivity) context ;
				activity.setDeleteData(true) ;
				activity.finish() ;			
			}
		}) ;
		
		View spacer1 = new View(context);
		View spacer2 = new View(context);
		
		spacer1.setId(8001) ;
		notesListButton.setId(8002) ;
		collectionsButton.setId(8003) ;
		deleteButton.setId(8004) ;
		spacer2.setId(8005) ;
		
		RelativeLayout.LayoutParams b1Params = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		RelativeLayout.LayoutParams b2Params = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		RelativeLayout.LayoutParams b3Params = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		RelativeLayout.LayoutParams s1Params = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		RelativeLayout.LayoutParams s2Params = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		
		b1Params.topMargin = 100 ;//addRule( RelativeLayout.BELOW, 8001) ;
		b1Params.leftMargin = 100 ;
		b1Params.rightMargin = 100 ;
		b2Params.leftMargin = 100 ;
		b2Params.rightMargin = 100 ;
		b3Params.topMargin = 200 ;
		b3Params.leftMargin = 100 ;
		b3Params.rightMargin = 100 ;
		b2Params.addRule( RelativeLayout.BELOW, 8002) ;
		b3Params.addRule( RelativeLayout.BELOW, 8003) ;
		s2Params.addRule( RelativeLayout.BELOW, 8004) ;		
		
		//lt.addView( spacer1, s1Params) ;
		lt.addView(notesListButton, b1Params ) ;
		lt.addView(collectionsButton, b2Params ) ;
		lt.addView(deleteButton, b3Params ) ;
		lt.addView( spacer2, s2Params) ;
		
		return lt ;
	}
	


}
